// 考勤设置管理
$(function() {
  $('#attendanceManagementList').getList({
    "initData": {
      "num": 1,
      "size": 10
    },
    "url": site.apiUrl + "/back/attendanceManagement/selectAttendanceManagementViewByCondition", // 数据请求url
    "type": "post",
    // "ajaxform": true,
    "checkname": "datachk", //选择器名称，为空不显示选择器
    "checkattr": [ //选择器上增加自定义属性，以便传递多个参数
      { "attr": "attendanceId", "value": "{{attendanceId}}" },
    ],
    "col": [ //数据列
      { "field": "checkingInName", "display": "考勤名称", "width": "1.5" },
      { "field": "equipmentName", "display": "考勤点", "width": "1.5" },
      { "field": "attendanceRange", "display": "考勤范围", "width": "1.5" },
      { "field": "attendanceStartTime", "display": "考勤开始时间", "width": "1.5" },
      { "field": "attendanceEndTime", "display": "考勤结束时间", "width": "1.5" },
      {
        "field": "isUsing",
        "display": "启用状态",
        "width": "1.5",
        "show": [ //数据自定义显示
          { "value": "0", "html": "禁用" },
          { "value": "1", "html": "启用" }
        ]
      }
    ],
    "option": [ //操作按钮配置
      /*{"icon":"view","tip":"查看","fun":"brandView('{{id}}')"},  //icon: view,edit,add,del*/
      { "icon": "edit", "tip": "编辑", "fun": "brandEdit('{{attendanceId}}')" }, // 花括号内可以对应相关字段
      { "icon": "del", "tip": "删除", "fun": "deleteBrand('{{attendanceId}}')" }
    ]
  });

  $("#isUsing").getSelect({
    type: "screen",
    label: "是否启用：",
    asName: "isUsing",
    code: "isUsing"
  });

  //批量删除
  $("#batchDelBtn").click(function() {
    var c = "";
    $("input[name=datachk]:checked").each(function() {
      c += $(this).attr('attendanceid') + ',';
    });
    if (c != null && c != '') {
      deleteBrand(c);
    } else {
      ly.toast("请选择删除项");
    }
  });
});
//编辑
function brandEdit(attendanceId) {
  ly.goto("attendanceManagement-creat.html?id=" + attendanceId + "&attendanceType=2")
}

//删除
function deleteBrand(attendanceId) {
  var url = site.apiUrl + "/back/attendanceManagement/deleteAttendanceManagement";
  ly.confirm("是否删除？", function() {
    request({
      url: url,
      data: { "ids": attendanceId },
      type: "post",
      ajaxform: 'true',
      callback: function(f) {
        if (f.code == "rest.success") {
          ly.toast("删除成功");
          $("#attendanceManagementList").getList.refresh(); //刷新当前分页
        }
      }
    });
  });
}

//查看
function commodityView(id) {
}

function changePic(v, o, d) {
  if (d.picDisplay != null && d.picDisplay != '') {
    $(o).html("<img src=" + d.picDisplay + " width='30' height='30'>");
  } else {
    $(o).html("<img src='" + site.interUrl + "images/default_head.jpg' width='30' height='30'>");
  }

}